package com.cxj.cxj_test_cloud.base.application;

import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import com.cxj.cxj_test_cloud.common.di.AppInjector;
import com.cxj.cxj_test_cloud.common.di.component.AppComponent;
import com.cxj.cxj_test_cloud.common.lifecycles.ActivityLifeCycles;

import javax.crypto.Mac;
import javax.inject.Inject;

import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasAndroidInjector;

public class BaseApplication extends Application implements HasAndroidInjector {
    //Android注入分发器
    @Inject
    DispatchingAndroidInjector<Object> androidInjector;
    private static AppComponent mAppComponent;
    private static Handler mManinHandler;


    public static AppComponent getAppComponent(){
        return mAppComponent;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
    }


    @Override
    public void onCreate() {
        super.onCreate();
        mManinHandler = new Handler(Looper.getMainLooper());
        mAppComponent = AppInjector.init(this);
        ActivityLifeCycles activityLifeCycles=new ActivityLifeCycles();
        this.registerActivityLifecycleCallbacks(activityLifeCycles);
    }

    public static Handler getMainHandler(){
        return mManinHandler;
    }

    @Override
    public AndroidInjector<Object> androidInjector() {
        return androidInjector;
    }
}
